<!-- 审批人每项 -->

<template>
  <div>
    <div class="flexCC" :class="colorClass">
      <div class="ellips2">{{ showText }}</div>
    </div>

    <div v-if="!isShow" class="CoreWeb-FormImage-del" @click="toDel"><i class="el-icon-close" /></div>
  </div>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import props from './props'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'UserItem',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [CORE.mixWeb()],

  /**
   * 属性注册 (抽取以便查阅)
   */
  props,

  /**
   * 计算属性 (慎用箭头函数)
   */
  computed: {
    /**
     * 颜色样式类
     */
    colorClass() {
      // const { obj: { approveType, approverSource } } = this
      // if (approveType === 2) return 'SuccessColor WhiteColor SuccessBgColor'
      // if (approveType === 3) return 'DangerColor WhiteColor DangerBgColor'
      // if (approverSource === 2) return 'PrimaryColor PrimaryBdColor PrimaryBgColor1'
      // if (approverSource === 3) return 'WarningColor WarningBdColor WarningBgColor1'
      return 'BlackColor BlackBdColor5'
    },

    /**
     * 显示文本
     */
    showText() {
      const { obj: { approveType, approverSource, approverUserName }, DICT } = this
      if (approveType !== 1) return CORE.dict(DICT.AUDIT_TYPE, approveType)
      if (approverSource !== 1) return CORE.dict(DICT.USER_SOURCE, approverSource)
      return approverUserName
    },
  },

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    /**
     * 删除
     */
    toDel() {
      const { one, obj } = this
      const check = (item) => item.id ? item.id === obj.id : item.time === obj.time
      const index = one.approvers.findIndex(check)
      one.approvers.splice(index, 1)
    },
  },
}
</script>
